<?php $this->pageTitle = CHtml::encode($issue->title) . ' - ' . Yii::app()->name ?>
  <ul class="breadcrumb">
    <li><a href="/"><i class="fa fa-home"></i> 首页</a></li>
    <li><a href="<?=Yii::app()->createUrl('issue/list')?>"><i class="fa fa-list-alt"></i> 问题列表</a></li>
    <li class="active"><a href=""><i class="fa fa-question"></i> 问题详情</a></li>
  </ul>
  <div class="panel panel-default">
    <div class="panel-heading"><i class="fa fa-question"></i> 问题详情</div>
    <div class="panel-body">
      <a href="<?= Yii::app()->createUrl('issue/post') ?>" class="btn btn-primary">在线提问</a>
      <article>
        <h2 class="title"><?= CHtml::encode($issue->title) ?></h2>
        <aside>
          <i class="fa fa-calendar"></i> <?= date('Y-m-d H:i:s', $issue->created_at) ?>
          状态：
          <?php if ($issue->state == 1): ?>
            <span class="label label-success">已解决</span>
          <?php else: ?>
            <span class="label label-warning">未解决</span>
          <?php endif ?>
        </aside>
        <div class="content"><?= nl2br(CHtml::encode($issue->content)) ?></div>
      </article>
    </div>
  </div>
  <div class="panel panel-info">
    <div class="panel-heading">
      <i class="fa fa-star"></i> 答案列表
    </div>
    <div class="panel panel-body">
      <?php if (empty($data['list'])): ?>
        还没有回答喔!
      <?php else: ?>
        <?php if($issue->state == 1):?>
          <article>
            <p><span class="label label-info">最佳答案</span>回答者：<?= CHtml::encode($issue->reply->user->name) ?>
              <?php if($issue->reply->user->type == 1):?>
                <span class="label label-info">学生</span>
              <?php elseif($issue->reply->user->type == 2):?>
                <span class="label label-info">教师</span>
              <?php else:?>
                <span class="label label-info">管理员</span>
              <?php endif?>
              回答时间：<?= date('Y-m-d H:i:s', $issue->reply->created_at) ?></p>
            <p><?= nl2br(CHtml::encode($issue->reply->content)) ?></p>
          </article>
          <hr/>
          <?php endif?>
        <?php foreach ($data['list'] as $row): ?>
            <?php if($row->reply_id == $issue->reply_id) continue?>
          <article>
            <p>回答者：<?= CHtml::encode($row->user->name) ?>
              <?php if($row->user->type == 1):?>
                <span class="label label-info">学生</span>
              <?php elseif($row->user->type == 2):?>
                <span class="label label-info">教师</span>
              <?php else:?>
                <span class="label label-info">管理员</span>
              <?php endif?>
              回答时间：<?= date('Y-m-d H:i:s', $row->created_at) ?></p>
            <p><?= nl2br(CHtml::encode($row->content)) ?></p>
            <?php if ($issue->user_id == Yii::app()->user->id && $issue->state == 0): ?>
              <a href="<?= Yii::app()->createUrl('issue/accept', array('issue_id'=>$issue->issue_id,'reply_id' => $row->reply_id)) ?>"
                 class="btn btn-success" onclick="return confirm('确定采纳这条答案吗?')">采纳</a>
            <?php endif ?>
          </article>
          <hr/>
          <?php
          $this->widget('CLinkPager', array(
              'pages' => $data['pages'],
              'htmlOptions' => array(
                  'class' => 'pagination'
              ),
              'firstPageLabel' => '首页',
              'lastPageLabel' => '末页',
              'nextPageLabel' => '下一页',
              'prevPageLabel' => '上一页',
              'footer' => '',
              'header' => '',
              'cssFile' => false
          ));
          ?>
        <?php endforeach ?>
      <?php endif ?>
    </div>
  </div>
<?php if (!Yii::app()->user->isGuest && Yii::app()->user->id != $issue->user_id && $issue->state == 0): ?>
  <div class="panel panel-success">
    <div class="panel-heading"><i class="fa fa-user"></i> 我来回答</div>
    <div class="panel-body">
      <form action="<?= Yii::app()->createUrl('issue/reply') ?>" method="post" class="form-horizontal">
        <?= CHtml::hiddenField('issue_id', $issue->issue_id) ?>
        <div class="form-group">
          <label class="col-md-1 control-label">回复:</label>

          <div class="col-md-8">
            <p class="form-control-static"><?= CHtml::encode($issue->title) ?></p>
          </div>
        </div>
        <div class="form-group">
          <label for="content" class="control-label col-md-1">答案</label>

          <div class="col-md-8">
            <textarea name="content" id="content" class="form-control" required="" rows="10"
                      placeholder="请输入你的答案"></textarea>
          </div>
        </div>
        <div class="form-group">
          <div class="col-md-2 col-md-offset-1">
            <button type="submit" class="btn btn-info btn-block">确定回答</button>
          </div>
        </div>
      </form>
    </div>
    <div class="panel-footer">您的答案或多或少会对提问者造成帮助，所以请不要恶意回答以免误导提问者</div>
  </div>
<?php endif ?>
<script>
  $(function(){
    initList();
  });
</script>